package com.hanggold.nx;

import com.hanggold.nx.bean.User;

import java.awt.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;

/**
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2019-07-31 15:44
 * @since
 **/
public class OnePropertyEditorDemo {

    public static void main(String[] args) {

        PropertyEditorManager.registerEditor(User.class, CustomPropertyEditor.class);

        PropertyEditor propertyEditor =   PropertyEditorManager.findEditor(User.class);

        propertyEditor.setAsText("xxx");

        propertyEditor.getValue();

        String text = propertyEditor.getAsText();

        System.out.printf("result: %s \n",text);

		String[] tags = propertyEditor.getTags();

		System.out.println(tags);

		propertyEditor.getValue();
    }


    public static class CustomPropertyEditor implements PropertyEditor {

        @Override
        public void setValue(Object value) {
            System.out.println("xxxxxxx");
        }

        @Override
        public Object getValue() {
            return "ssss";
        }

        @Override
        public boolean isPaintable() {
            return false;
        }

        @Override
        public void paintValue(Graphics gfx, Rectangle box) {
        }

        @Override
        public String getJavaInitializationString() {
            return null;
        }

        @Override
        public String getAsText() {
            return "xxxxxx";
        }

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            System.out.println("设置值");
        }

        @Override
        public String[] getTags() {
            return new String[0];
        }

        @Override
        public Component getCustomEditor() {
            return null;
        }

        @Override
        public boolean supportsCustomEditor() {
            return false;
        }

        @Override
        public void addPropertyChangeListener(PropertyChangeListener listener) {
			System.out.println(listener);

        }

        @Override
        public void removePropertyChangeListener(PropertyChangeListener listener) {
			System.out.println(listener);
        }
    }

}
